
const baseUrl = 'https://api-hmugo-web.itheima.net/api/public/v1'

const request = ( { url, method='get', data = {} } ) => {
	return new Promise( (resolve, reject) => {
		uni.request({
			url:url,
			method,
			data,
			success: (res) => {
				resolve(res.data)
			},
			fail: (err) => {
				reject(err)
			}
		})
	} )
}

uni.addInterceptor('request', {
  invoke(args) {
    // request 触发前拼接 url 
    args.url = baseUrl + args.url
  },
  success(args) {
    // 请求成功后，修改code值为1
    // args.data.code = 1
	console.log('arg2' , args);
  }, 
  fail(err) {
    // console.log('interceptor-fail',err)
  }, 
  complete(res) {
    // console.log('interceptor-complete',res)
  }
})

export default request